local DIY = require "packages.diy_utility.diy_utility"

local skel = fk.CreateSkill{
  name = "sj_dianjuren__zaodonglianju",
}

Fk:loadTranslationTable{
  ["sj_dianjuren__zaodonglianju"] = "躁动链锯",
  [":sj_dianjuren__zaodonglianju"] = "出牌阶段，你可以重铸两张牌，然后将因此法获得的一张牌当一张不计入次数限制的雷【杀】使用，结算后，若中央区含有四种花色，本回合本技能失效，然后你失去1点体力。",
  ["#sj_dianjuren__zaodonglianju"] = "躁动链锯：你可以重铸两张牌，然后将因此法获得的一张牌当雷【杀】使用",
  ["#sj_dianjuren__zaodonglianju_slash"] = "躁动链锯：你可以将一张牌当雷【杀】使用",
}

skel:addEffect("active", {
  prompt = "#sj_dianjuren__zaodonglianju",
  target_filter = Util.FalseFunc,
  card_filter = function (self, player, to_select, selected, selected_targets)
    return #selected < 2
  end,
  card_num = 2,
  min_card_num = 2,
  max_card_num = 2,
  can_use = function (self, player)
    return #player:getCardIds("he") > 1
  end,
  on_use = function (self, room, effect)
    local player = effect.from
    local cards = room:recastCard(effect.cards,player,skel.name)
    local use = false
    for _, id in ipairs(cards) do
      if table.contains(player:getCardIds("he"),id)  then
        use = true
        break
      end
    end
    if use then
      room:askToUseVirtualCard(player,{
        name = "thunder__slash",
        skill_name = skel.name,
        prompt = "#sj_dianjuren__zaodonglianju_slash",
        cancelable = false,
        card_filter = {
          n = 1,
          pattern = tostring(Exppattern{ id = cards }),
        },
        extra_data = {bypass_times = false},
      })
    end
    local suit = {}
    for _, id in ipairs(DIY.getCenterCards(room)) do
      table.insertIfNeed(suit,Fk:getCardById(id).suit)
    end
    if #suit > 3 then
      room:invalidateSkill(player,skel.name,"-turn")
      if not player.dead then
        room:loseHp(player,1,skel.name)
      end
    end
  end,
})

skel:addAcquireEffect(function (self, player, is_start)
  player.room:addSkill("#CenterArea")
end)

return skel